/**
 * @Date 2025/3/4 10:24
 * @Created by 衡盛永
 */

package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

/**
 * 地址管理
 */
@RestController
@RequestMapping("/user/addressBook")
@Api(tags = "地址管理相关接口")
@Slf4j
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;

    /**
     * 获取收货地址列表
     *
     * @return
     * @params
     */
    @GetMapping("/list")
    public Result<List<AddressBook>> addressBooks() {
        List<AddressBook> addressBooks = addressBookService.list(8L);
        return Result.success(addressBooks);
    }

    /**
     * 新增收货地址
     *
     * @params: cityCode: "1101"
     * cityName: "市辖区"
     * consignee: "衡2"
     * detail: "1111"
     * districtCode: "110107"
     * districtName: "石景山区"
     * label: 1
     * name: "衡2"
     * phone: "15083122581"
     * provinceCode: "11"
     * provinceName: "北京市"
     * sex: "0"
     * type: 1
     */
    @PostMapping("")
    public void addAddressBook(@RequestBody AddressBook addressBook) {
        addressBookService.save(addressBook);
    }


    /**
     * 默认收货地址
     *
     * @return
     */
    @GetMapping("/default")
    @ApiOperation("默认收货地址")
    public Result<AddressBook> defaultAddress() {
        Long userId = BaseContext.getCurrentId();
        AddressBook addressBook = addressBookService.defaultAddress(8L);
        return Result.success(addressBook);
    }
}
